/**
 * @param {string} s
 * @return {string}
 */
 var longestPalindrome = function (s) {
    if (s.length <= 0) return s
    let start = 0
    let maxLength = 0
    function fn(l, r) {
      while (l >= 0 && r <= s.length && s[l] === s[r]) {
        if (r - l + 1 > maxLength) {
          maxLength = r - l + 1
          start = l
        }
        l--
        r++
      }
    }
    for (let i = 0; i < s.length; ++i) {
      fn(i, i) // 奇数
      fn(i, i + 1) // 偶数
    }
    return s.substring(start, start + maxLength)
  };